<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>菜单管理</title>
<link rel="stylesheet" type="text/css" href="${request.contextPath}/resources/js/jquery-treetable/jquery.treetable.css" />
<link rel="stylesheet" type="text/css" href="${request.contextPath}/resources/js/jquery-treetable/jquery.treetable.theme.default.css" />

<script type="text/javascript" src="${request.contextPath}/resources/js/jquery-treetable/jquery.treetable.js"></script>
<script>


//查询菜单信息	
var searchMeunData =function()
{
	$.ajax({
		url:'${request.contextPath}/menu/getMenuList.htm',
		type:'post',
		dataType:'html',
		async:'false',
		cache:false,
		processData:true,
		success:function(html)
		{
			$('#dataDiv').html(html);
		}
	});
}

//打开添加菜单的模态框
var addMenuDiv = function()
{
	$('#addModal').modal();
	queryParentMenu();
}

//添加菜单
var addMenuFn = function()
{
	$.ajax({
		url:'${request.contextPath}/menu/addMenu.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		data:$('#addForm').serialize(),
		success:function(data)
		{
			alert(data.msg);
			if(data.success==1)
			{
				searchMeunData();
				$('#addModal').modal('hide');
			}
		}
	});
}


//删除菜单
var removeMenuFn = function(id)
{
	if(!confirm('确认删除该菜单么？'))
	{
		return false;
	}
	$.ajax({
		url:'${request.contextPath}/menu/removeMenu.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		data:{
			'menuId':id
		},
		success:function(data)
		{
			alert(data.msg);
			if(data.success==1)
			{
				searchMeunData();
			}
		}
	});
}


//查询父菜单
var queryParentMenu = function(){

	$.ajax({
		url:'${request.contextPath}/menu/queryParentMenu.htm',
		type:'post',
		dataType:'json',
		async:'false',
		cache:false,
		processData:true,
		success:function(data)
		{
			console.log(data.menuList);
			var html = '';
			html += '<select name="parentId">'
				 + '<option value="0">无</option>';
			 
			$.each(data.menuList,function(n,value){
				html += '<option value="'+value.id+'">'+value.menuName+'</option>';
			});
			html += '</select>'
			$("#parentMeunListSelect").html(html);
		},
		beforeSend:function(XMLHttpRequest)
		{
		  
		  $("#parentMeunListSelect").html('<img src="${request.contextPath}/resources/images/loading.gif"></img>');
		  $('#parentMeunListSelect').show();
		},
		afterSend:function()
		{
		  $("#parentMeunListSelect").html('');
		}
	});
}
searchMeunData();

</script>
</head>
<body>
<span class="cp_title">菜单管理</span>
<br/>
<br/>
<div id="dataDiv">
</div>

<div class="modal fade" id="addModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" 
               data-dismiss="modal" aria-hidden="true">
                  &times;
            </button>
            <h4 class="modal-title" id="myModalLabel">
            	添加菜单
            </h4>
         </div>
         <div class="modal-body">
           	<form id="addForm">
           		<table class="table">
           			<tr>
           				<td  width="20%">
           				父菜单：
           				</td>
           				<td  width="30%" id="parentMeunListSelect">
	           				<select name="parentId">
	           					<option value="0">无</option>
	           					<#list parentMeunList as menu>
	           						<option value="${menu.id}">${menu.menuName}</option>
	           					</#list>
	           				</select>
           				</td>
           				
           				<td width="20%">
           				菜单名：
           				</td>
           				<td width="30%">
           				<input name="menuName"/>
           				</td>
           				

           			</tr>
           			<tr>
           				<td>
           				菜单路径：
           				</td>
           				<td>
           				<input name="menuUrl"/>
           				</td>
           				<td>
           				菜单权重：
           				</td>
           				<td>
           				<input name="menuOrder"/>
           				</td>
           				

           			</tr>
           		</table>
           	</form>
         </div>
         <div class="modal-footer">
            <button type="button" class="btn btn-default" 
               data-dismiss="modal">关闭
            </button>
            <button type="button" class="btn btn-primary" onclick="addMenuFn();">
              	 提交更改
            </button>
         </div>
      </div>
</div>


</body>
</html>
